package zz.servlet;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LogoutServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        int count2 = (int) getServletContext().getAttribute("count2");
        count2--;
        getServletContext().setAttribute("count2",count2);

        HttpSession session = request.getSession();
        session.invalidate();//session失效
        session.setMaxInactiveInterval(10);
//        request.getSession().invalidate();
        request.setAttribute("error","登录失败");
        response.sendRedirect(request.getContextPath() + "/logout.jsp");
    }
    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException {
        doPost(request,response);
    }
}
